<?php
	if (isset($_REQUEST['maGianHang']) && is_numeric($_REQUEST['maGianHang']))
	{
		require_once ('class/GianHangDAO.php');	
		require_once ('class/LikesDAO.php');		
		
		$maGH = $_REQUEST['maGianHang'];
		$gianHangDto = GianHangDAO::LayGianHangTheoMa($maGH, 0);	
		$gianHangDtoXML = GianHangDAO::LayThongTinGianHang_XML($maGH);
		if (is_null($gianHangDto))
		{
			header("Location:ds_gian_hang.php");
		}
		else
		{
			//kiểm tra đăng nhập hay chưa, chưa thì tăng biến xem lượt gian hàng
			if ($_SESSION['IsLogin'] == 1)
			{
				$luotXemGH = $_SESSION['LuotXemGianHang'];
				if (!in_array($maGH,$luotXemGH))
				{	
					array_push($luotXemGH, $maGH);
				}	
				$_SESSION['LuotXemGianHang'] = $luotXemGH;
			}
		}
	}
	else
	{
		header("Location:ds_gian_hang.php");
	}
	
?>
<div class="header-shop">
	<div class="header-left">
    	<a href="index.php">Shopping HERE</a>
    </div>
    <!--end .header-left-->    
    <div class="header-right">
    	<?php require_once('controls/ucMenu_Header.php'); ?>
        <!--end .header-navigator-->	       
    </div>
    <!--end .header-right-->
  </div>
  <!--end .header-->
  <div class="banner-shop">
  	<div class="back-ground">    	
   	  	<?php 
			//BANNER
			if (is_file($gianHangDtoXML->Banner))
			{
				echo "<img src='$gianHangDtoXML->Banner' width='1000' height='100' />";
			}
		?>
  	 </div>
  </div>
  <!--end .banner-shop-->
  <div class="slogan-shop">
  	<div class="content ui-corner-all">
    	
    	<?php 
		//tên + slogan
		echo '<div class="top-shop-info-line">
				<div class="name">
					<span class="text-color-bold-1">WELCOME TO </span> 
						<a href="gian_hang.php?maGianHang='.$maGH.'">"'.$gianHangDtoXML->TenGianHang.'"</a>
			  	</div>
			  </div>';
		if (strlen($gianHangDtoXML->Slogan) > 0)
		{
			echo '<div class="text-color-normal-1">
					'.$gianHangDtoXML->Slogan.'
				  </div>';
		}
		?>	 
    </div>
  </div>
  <!--end .slogan-shop-->
  <div class="menu-shop-wrapper">
	 <div class="menu-shop">
        <ul>
            <li><a href="gian_hang.php?maGianHang=<?php echo $maGH ?>">Trang chủ</a></li>
            <li><a href="ds_san_pham.php?maGianHang=<?php echo $maGH ?>">Sản phẩm</a></li>
            <li><a href="ds_su_kien.php?maGianHang=<?php echo $maGH ?>">Sự kiện</a></li>
          	<li><a href="gian_hang.php?maGianHang=<?php echo $maGH ?>">Về gian hàng</a></li>            
        </ul>
        <!--end ul menu-->            
     </div>
     <!--end .menu-shop-->
     <?php
	 $dsLikeGianHang = LikesDAO::LayDanhSachLikesTheoMaDoiTuong($gianHangDto->MaGianHang);	
	  $soNguoiLikeGH = count($dsLikeGianHang);
	  $funcLikeGH = 'funcLike("'.$gianHangDto->MaGianHang.'",
								"'.$_SESSION['IdUser'].'","kq_like_gh", "Like_GH_gian_hang")';
	  $nguoiDungLikeGH = LikesDAO::LayDanhSachLikesTheoMaDT_MaNguoiDung(
							$gianHangDto->MaGianHang, $_SESSION['IdUser']);
	  if (is_null($nguoiDungLikeGH))
	  {
		  $btnLikeGH = "Like";
	  }
	  else
	  {
		  $btnLikeGH = "Unlike";
	  }
	  $funcNhanEmail = 'funcNhanEmail("'.$_SESSION['IdUser'].'","'.$gianHangDto->MaGianHang.'","Email_gian_hang")';
	  $btnNhanEmail = "";
	  if (GianHangDAO::KiemTraDangKyNhanEmail($_SESSION['IdUser'], $gianHangDto->MaGianHang))				  		  
		   $btnNhanEmail = "Hủy nhận email";		 
	  else
		  $btnNhanEmail = "Đăng ký nhận email";	
 
	 
	 ?>
     <div class="menu-search">
     	 <ul>
         	<li id='kq_nhan_email'>
				<?php 
				echo "<label><span onclick='".$funcNhanEmail."' >$btnNhanEmail </span></label>"; 
				?>
            </li>
            <li id='kq_like_gh'>
				(<?php echo $soNguoiLikeGH; ?>)
               	|
				<?php 
				echo "<label><span onclick='".$funcLikeGH."' >$btnLikeGH</span></label>";
				?>                 
                &nbsp; &nbsp;&nbsp; &nbsp; 
            </li>
          </ul>
     </div>
     <!--end .menu-search-->
  </div>
  <!--end .menu-shop-wrapper-->

